/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jmail;

import java.util.Properties;
import javax.mail.Session;

/**
 *
 * @author iflamed
 */
public class MailSession {

    private String username;
    private String password;
    private Properties prop;

    public MailSession(String pop3server, String protocol, String username, String password) {
        this.username = username;
        this.password = password;
        prop = new Properties();
        this.prop.put("mail.store.protocol", protocol);
        this.prop.put("mail.pop3.host", pop3server);
    }

    public Session getSession() {
        try {
            return Session.getDefaultInstance(this.prop, new MailAuthenticator(this.username, this.password));
        } catch (SecurityException se) {
            return Session.getInstance(prop, new MailAuthenticator(this.username, this.password));
        }
    }
}
